
Imports SAPBoAddon.B1AddonBase
Namespace BoAddonBiz_Authorisation
    Public Class B1Console_Authoristation
        Inherits SAPBoAddon.B1BusinessConsole
        Private Shared _CanUse As Boolean = False

        Public Shared ReadOnly Property CanUse As Boolean
            Get
                Return _CanUse
            End Get
        End Property


        Protected Overrides Sub RegisterForms()
            Dim target As New SAPBoAddon.BoAddonBiz_Authorisation.B1Form_AU_TARGET
            Dim Authorisation As New SAPBoAddon.BoAddonBiz_Authorisation.B1Form_AU_Authorisation
        End Sub

        Protected Overrides Sub RegisterMenus()
            Dim AuMenus As New SAPBoAddon.BoAddonBiz_Authorisation.B1Menus_Authorisations
        End Sub


        Public Overrides Function CheckEnvironment() As Boolean
            Dim oRs As SAPbobsCOM.Recordset
            Dim sql_CheckTable As String = "SELECT *  FROM OUTB T0 Where T0.TableName = '%0'"
            Dim msg As String
            Try
                oRs = SAPBoAddon.B1Addon.B1Addon.SBOAddOn.GetRecordset
                oRs.DoQuery(sql_CheckTable.Replace("%0", "AVA_AU_TARGET"))
                If oRs.RecordCount = 0 Then
                    msg = "Not found table [%0]. ".Replace("%0", "AVA_AU_TARGET")
                    SAPBoAddon.B1Addon.B1Addon.SBOAddOn.StatusBarMessage("Authorisation can not be started." & msg, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
                    _CanUse = False
                    Return False
                End If
                oRs.DoQuery(sql_CheckTable.Replace("%0", "AVA_AU_AUTHORISE"))
                If oRs.RecordCount = 0 Then
                    msg = "Not found table [%0]. ".Replace("%0", "AVA_AU_AUTHORISE")
                    SAPBoAddon.B1Addon.B1Addon.SBOAddOn.StatusBarMessage("Authorisation can not be started." & msg, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
                    _CanUse = False
                    Return False
                End If
                _CanUse = True
                Return True
            Catch ex As Exception
                _CanUse = False
                Return False
            End Try
        End Function

        Protected Overrides Sub RegisterOthers()
            B1AuthorisationServer.CreateInstance()
        End Sub
    End Class
End Namespace

